<?php

class UserLogin extends ActionBase {
    public $title = 'Login';

    function login(){
        include_once VALIDATEUSER;
        if(loginFieldsValid()){
            $this->isUserExist();
        }else{
            include_once  BASEURL.'web/layout.php';
        }
    }

    function isUserExist(){
        if($this->getLoginService() != null){
            $result =  $this->loginService->isUserExist($_POST['user'], md5( $_POST['pass'] ));
            if($result){
                $_SESSION['is_loged'] = md5('SempleUserIsLogedIn');
                $_SESSION['user'] =  md5($_POST['pass']);
                $_SESSION['userName'] =  $_POST['user'];

                $_REQUEST['request']['object'] = 'gallery';
                $_REQUEST['request']['action'] = 'list';
                include_once BASEURL.'action/gallery/wrapper.php';
                new GalleryWrapper();
            }else{
                unset($_SESSION['is_loged']);
                unset($_SESSION['user']);

                $_REQUEST['request']['object'] = 'gallery';
                $_REQUEST['request']['action'] = 'list';
                include_once BASEURL.'action/gallery/wrapper.php';
                new GalleryWrapper();
            }
        }
    }


    public function UserLogin(){
        $this->login();
    }
}

?>